package com.win.oauth.service;

import com.fyl.schedule.JobDefinition;
import com.win.oauth.entity.Task;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.Objects;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author fyl
 * @since 2020-09-05
 */
public interface ITaskService extends IService<Task> {

    public static final String DEFAULT_JOB_GROUP = "DEFAULT_JOB_GROUP";
    public static final String DEFAULT_JOB_METHOD = "execute";
    public static final Integer DISALLOW_CONCURRENT_EXEC = 1;
//    public static final Integer ALLOW_CONCURRENT_EXEC = 0;

    public static final Integer JOB_RUN_STATUS = 1;
//    public static final Integer JOB_STOP_STATUS = 0;

    default JobDefinition buildJob(Task entity) {

        JobDefinition jobDefinition = new JobDefinition();

        jobDefinition.setJobGroup(entity.getJobGroup());
        jobDefinition.setJobName(entity.getJobName());
        jobDefinition.setCron(entity.getCron());
        jobDefinition.setDisallowConcurrentExecution(Objects.equals(entity.getDisallowConcurrentExecution(), DISALLOW_CONCURRENT_EXEC));

        jobDefinition.setClazz(entity.getClazz());
        jobDefinition.setMethod(entity.getMethod());

        return jobDefinition;
    }

}
